﻿Public Class Utils
    Shared Function getViewState(ByVal s As String) As String
        Dim viewstate As String = ""
        Dim viewstateMatch = System.Text.RegularExpressions.Regex.Match(s, "(?<=id=""__VIEWSTATE"" value="")[^""]*")
        If viewstateMatch.Success Then
            viewstate = viewstateMatch.Value
        End If
        Return viewstate
    End Function

    Shared Function getEventValidation(ByVal s As String) As String
        Dim eventValiadation As String = ""
        Dim eventValidationMatch = System.Text.RegularExpressions.Regex.Match(s, "(?<=id=""__EVENTVALIDATION"" value="")[^""]*")
        If eventValidationMatch.Success Then
            eventValiadation = eventValidationMatch.Value
        End If
        Return eventValiadation
    End Function

    Shared Function UnZip(ByVal value() As Byte) As String

        Dim mem2 As New IO.MemoryStream(value)
        Dim gz = New System.IO.Compression.GZipStream(mem2, IO.Compression.CompressionMode.Decompress)
        Dim sr As New IO.StreamReader(gz)
        Dim st = sr.ReadToEnd
        sr.Close()
        Return st

        'stm.Read(

        'stm.Read

        'Transform string into byte[]
        'Dim byteArray As Byte() = New Byte(value.Length - 1) {}
        'Dim indexBA As Integer = 0
        'For Each item As Char In value.ToCharArray()
        '    byteArray(System.Math.Max(System.Threading.Interlocked.Increment(indexBA), indexBA - 1)) = CByte(AscW(item))
        'Next

        ''Prepare for decompress
        'Dim ms As New System.IO.MemoryStream(byteArray)
        'Dim sr As New System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress)

        ''Reset variable to collect uncompressed result
        'byteArray = New Byte(byteArray.Length - 1) {}

        ''Decompress
        'Dim rByte As Integer = sr.Read(byteArray, 0, byteArray.Length)

        ''Transform byte[] unzip data to string
        'Dim sB As New System.Text.StringBuilder(rByte)
        ''Read the number of bytes GZipStream red and do not a for each bytes in
        ''resultByteArray;
        'For i As Integer = 0 To rByte - 1
        '    sB.Append(CChar(ChrW(byteArray(i))))
        'Next
        'sr.Close()
        'ms.Close()
        'sr.Dispose()
        'ms.Dispose()
        'Return sB.ToString()
    End Function
End Class
